package com.feicheng.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import com.feicheng.common.token.TokenContainer;
import com.feicheng.service.IFCheckCodeService;
import com.feicheng.service.IFOrderService;

import lombok.extern.slf4j.Slf4j;

@Configuration
@EnableScheduling
@Slf4j
public class TokenScheduleTask {

    @Autowired
    TokenContainer tokenContainer;

    @Autowired
    IFOrderService ifOrderService;

    @Autowired
    IFCheckCodeService ifCheckCodeService;

    @Scheduled(cron = "0 */5 * * * ?")
    private void cleanToken() {
        try {
        	tokenContainer.cleanContainer();
        } catch (Exception e) {
        	log.error("清除token出现问题", e);
        }
        
    }
    
    @Scheduled(cron = "0 */3600 * * * ?")
    private void checkOrder() {
        try {
        	ifOrderService.consumeTooLongOrder();
        } catch (Exception e) {
        	log.error("定时结算订单出现问题", e);
        }
        
    }

    @Scheduled(cron = "0 */11 * * * ?")
    private void cleanCmd() {
        try {
        	ifCheckCodeService.cleanCmd();
        } catch (Exception e) {
        	log.error("清理失效命令出现问题", e);
        }
        
    }
}
